package com.edu.chat.web.covert;

import cn.hutool.core.date.DateUtil;
import com.edu.buservice.util.model.TenantUtil;
import com.edu.chat.facade.model.dto.RecallResDTO;
import com.edu.chat.facade.model.enums.SourceEnum;
import com.edu.chat.web.controller.vo.ArticleVO;
import com.edu.chat.web.dto.ArticleDTO;
import com.edu.chat.web.dto.SearchArticleDTO;
import com.edu.chat.web.model.ArticleEntity;
import com.edu.chat.web.model.CsArticle;

import java.util.Optional;

/**
 * @program: KQAIA
 * @description:
 * @author: 无恙
 * @create: 2025-03-20 22:41
 **/


public class ArticleCovert {

	public static ArticleDTO covert(CsArticle csArticle){
		ArticleDTO articleDTO = new ArticleDTO();
		articleDTO.setId(String.valueOf(csArticle.getId()));
		articleDTO.setLibraryId(String.valueOf(csArticle.getLibraryId()));
		articleDTO.setCategoryId(String.valueOf(csArticle.getCategoryId()));
		articleDTO.setContentType(csArticle.getContentType());
		articleDTO.setTitle(csArticle.getTitle());
		articleDTO.setContent(csArticle.getContent());
		articleDTO.setUpdateTime(DateUtil.formatDateTime(csArticle.getUpdatedAt()));
		return articleDTO;
	}


	public static CsArticle covert(ArticleVO articleVO){
		CsArticle csArticle = new CsArticle();
		Optional.ofNullable(articleVO.getId()).ifPresent(id->csArticle.setId(Long.valueOf(articleVO.getId())));
		csArticle.setLibraryId(Long.valueOf(articleVO.getLibraryId()));
		csArticle.setCategoryId(Long.valueOf(articleVO.getCategoryId()));
		csArticle.setContentType(articleVO.getContentType());
		csArticle.setTitle(articleVO.getTitle());
		csArticle.setContent(articleVO.getContent());
		return csArticle;

	}

	public static ArticleEntity covertToArticleEntity(ArticleVO articleVO){
		ArticleEntity entity =new ArticleEntity();
		entity.setArticleId(articleVO.getId());
		entity.setTitle(articleVO.getTitle());
		entity.setContent(articleVO.getContent());
		entity.setTenantId(TenantUtil.getTenantId());
		entity.setLibraryId(articleVO.getLibraryId());
		return entity;

	}

	public static RecallResDTO covertToRecallRes(SearchArticleDTO searchArticleDTO){
		RecallResDTO recallResDTO = new RecallResDTO();
		recallResDTO.setContent(searchArticleDTO.getContent());
		recallResDTO.setConfidence(searchArticleDTO.getScore());
		recallResDTO.setTenantId(searchArticleDTO.getTenantId());
		recallResDTO.setSourceId(String.valueOf(searchArticleDTO.getArticleId()));
		recallResDTO.setSource(SourceEnum.ARTICLE.getCode());
		return recallResDTO;
	}
}
